#version 330 core

uniform sampler2D DecalTexture;

in vec4 FogParam;
in vec3 InterpNormal;
in vec2 InterpTexCoord;
in vec3 InterpViewDir;
in vec3 InterpLightDir;

out vec4 FragmentColor;

void main(void)
{
    
    vec4 color = texture( DecalTexture, InterpTexCoord );
    
    /* discard fragments with small alpha (alpha testing for leaf texture) */
    if (color.a < 0.5) discard;

    /* normalize and calculate vectors needed for light computation */
    vec3 Normal = normalize(InterpNormal);
    vec3 ViewDir = normalize(InterpViewDir);
    vec3 LightDir = normalize(InterpLightDir);
    vec3 Reflection = reflect(LightDir, Normal);

	/* calculate basic phong lighting */
	float Diffuse = clamp(dot(Normal, LightDir), 0.0, 1.0);
	float Specular = pow(clamp(dot(Reflection, ViewDir), 0.0, 1.0), 4);
	
	/* accumulate final fragment color */
  	FragmentColor = mix( color * ( 0.3 + Diffuse + Specular ), FogParam, FogParam.w );

}
